function main(json) {
  const clone = (json) => JSON.parse(JSON.stringify(json));
  const transNum = (s) => {
    if (!s) return '--';
    const val = (s + '').trim();

    const num = Number(val);

    if (isNaN(num)) return '--';
    return (num * 100).toFixed(3) + '%';
  };
  function genStr(name, { beforePrice, price, down }) {
    if (!price || price == '') return undefined;
    const downPrice = !!beforePrice
      ? parseFloat(beforePrice) - parseFloat(price)
      : '--';
    const str = `Q3价格：${price}; Q3-1价格：${
      beforePrice || '--'
    }; 降价：${downPrice}; 降幅：${transNum(down)}`;
    return str;
  }
  const data = Object.values(json)[0];
  const head = data[0];

  const rowLen = head.length;

  let currentMonth = undefined;
  let currentGoods = undefined;

  const result = [
    ['物料维度', '供方', '采购方', '单位', '当月均价', '当月数量'],
  ];
  // 遍历body
  for (let i = 1; i < data.length; i++) {
    const row = data[i];
    const rowInfo = {};
    const companyMap = new Map();
    for (let j = 0; j < rowLen; j++) {
      if (j == 0) {
        if (row[j]) {
          currentMonth = row[j];
        }
        rowInfo.month = currentMonth;
      } else if (j == 1) {
        if (row[j]) {
          currentGoods = row[j];
        }
        rowInfo['goods'] = currentGoods;
      } else if (j == 2) {
        rowInfo['supplier'] = row[j];
      } else if (j == 3) {
        rowInfo['unit'] = row[j];
      } else {
        if (row[j]) {
          const currentHead = head[j];
          const currentName = currentHead.slice(0, -4);
          let target = companyMap.get(currentName);
          if (!target) {
            target = { orderBy: currentName };
            companyMap.set(currentName, target);
          }
          if (currentHead.includes('单价')) {
            target['price'] = row[j];
          } else {
            target['quantity'] = row[j];
          }
          const next = row[j + 1];
          if (!next) {
            result.push([
              rowInfo.goods,
              rowInfo.supplier,
              target.orderBy,
              rowInfo.unit,
              target.price || '/',
              target.quantity || '/',
            ]);
          } else {
            const nextHead = head[j + 1];
            const nextName = nextHead.slice(0, -4);
            if (nextName !== currentName) {
              result.push([
                rowInfo.goods,
                rowInfo.supplier,
                target.orderBy,
                rowInfo.unit,
                target.price || '/',
                target.quantity || '/',
              ]);
            }
          }
        }
      }
    }
  }

  return { sheet1: result };
}

export default main;
